package com.blb.thread;

public class Test5 {
    static int num,num1;
    static Object object=new Object();
    public static void main(String[] args) {
        new Thread(()->{
           synchronized (object){
               object.notifyAll();
               while(num<10){
                   System.out.print(0);
                   object.notifyAll();
                   try {
                       object.wait();
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
                   num++;
               }
           }
        }).start();

        new Thread(()->{
            synchronized (object){
//                object.notifyAll();
                while(num1<10){
                    System.out.print(1);
                    object.notifyAll();
                    try {
                        object.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    num1++;
                }
                if(num1==10){
                    return;
                }
            }
        }).start();
    }
}
